package cn.source.controller;

import cn.source.common.core.controller.BaseController;
import cn.source.domain.Vo.BigScreenDisplayVO;
import cn.source.mapper.UserArticlePointsMapper;
import cn.source.system.mapper.SysUserMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/data")
public class BigScreenDisplayController extends BaseController
{
    @Autowired
    private UserArticlePointsMapper pointsMapper;

    @Autowired
    private SysUserMapper userMapper;
    /**
     * 获取大屏数据
     */
    @GetMapping
    public ResponseEntity<BigScreenDisplayVO> getData() {
        BigScreenDisplayVO bigScreenDisplay = new BigScreenDisplayVO();
        //查询用户浏览文章的标题与积分获取情况
        List<Map<String, Object>> userOpints = pointsMapper.selectUserArticlePoints();
        // 查询从当前月至前11个月的各月份总获得积分
        List<Map<String, Object>> monthOpints = pointsMapper.selectPointsByNowMonth();
        //查询各党员类型人数
        List<Map<String, Object>> countPartyType = userMapper.selectCountPartyType();
        //计算party_standing到现在的时间差，并统计各阶段的记录数
        List<Map<String, Object>> partyStanding = userMapper.countUserByPartyStandingRange();
        List<Map<String, Object>> usersByAgeRange = userMapper.countUsersByAgeRange();
        bigScreenDisplay.setUserOpints(userOpints);
        bigScreenDisplay.setMonthOpints(monthOpints);
        bigScreenDisplay.setCountPartyType(countPartyType);
        bigScreenDisplay.setPartyStanding(partyStanding);
        bigScreenDisplay.setUsersByAgeRange(usersByAgeRange);
        return ResponseEntity.ok(bigScreenDisplay);
    }


}
